import http from '../utils/request'
import {getToken} from "@/utils/cookies.js"

const token = getToken();
// 请求首页数据,直接把这个对象导出
export const getData = () => {
    // 返回一个promise
    return http.get('/home/getData')
}

// 下面四个:用户管理-后端-网络请求接口
export const getUser = (params) => {
    return http.get('/user/get/', params)
}

export const createUser = (data) => {
    return http.post('/user/create', data)
}


// 登录权限
// export const login = (data) => {
//     return http.post('/permission/getMenu',data)
// }
export const getMenu = () => {
    const token = getToken();
    const params = {
        headers: {
            'Authorization': `Bearer ${token}` // 使用模板字符串
        }
    }
    return http.get('/api/getMenu', params)
}
export const login = (data) => {
    return http.post('/auth/login', data)
}

export const getAllMenu = () => {
    const token = getToken();
    const params = {
        headers: {
            'Authorization': `Bearer ${token}` // 使用模板字符串
        }
    }
    return http.get('/api/getAllMenu', params)
}

export const getMenuById = (menuId) => {
    const token = getToken();
    const params = {
        headers: {
            'Authorization': `Bearer ${token}` // 使用模板字符串
        },
        params: {
            menuId: menuId
        }
    }
    return http.get('/api/getMenuById', params);
}

export const insertMenu = (data) => {
    const token = getToken();
    const params = {
        headers: {
            'Authorization': `Bearer ${token}` // 使用模板字符串
        }
    }
    return http.post('/api/insertMenu', data, params);
}

export const updateMenu = (data) => {
    const token = getToken();
    const params = {
        headers: {
            'Authorization': `Bearer ${token}` // 使用模板字符串
        }
    }
    return http.post('/api/updateMenu', data, params);
}

export const deleteByMenuId = (menuId) => {
    const token = getToken();
    const params = {
        headers: {
            'Authorization': `Bearer ${token}` // 使用模板字符串
        },
        params: {
            menuId: menuId
        }
    }
    return http.get('/api/deleteMenu', params);
}

export const getUserByPage = (data) => {
    const token = getToken();
    const params = {
        headers: {
            'Authorization': `Bearer ${token}` // 使用模板字符串
        }
    }
    return http.post(`/api/getUserByPage?pageNum=${data.pageNum}&pageSize=${data.pageSize}`, data.user,params);
}

export const resetUserPassword = (data) => {
    const token = getToken();
    const params = {
        headers: {
            'Authorization': `Bearer ${token}` // 使用模板字符串
        }
    }
    return http.post('/api/resetPassword', data,params);
}

export const deleteUser = (userIds) => {
    const token = getToken();
    const params = {
        headers: {
            'Authorization': `Bearer ${token}` // 使用模板字符串
        },
        params: {
            userIds: userIds
        }
    }
    return http.get('/api/deleteUser',params);
}

export const updateUser = (data) => {
    const token = getToken();
    const params = {
        headers: {
            'Authorization': `Bearer ${token}`, // 使用模板字符串
            "Content-Type": "multipart/form-data",
        }
    }
    return http.post('/api/updateUser', data, params);
}

export const insertUser = (data) => {
    const token = getToken();
    const params = {
        headers: {
            'Authorization': `Bearer ${token}` // 使用模板字符串
        }
    }
    return http.post('/auth/register', data, params);
}

export const uploadUser = (data) => {
    const token = getToken();
    const params = {
        headers: {
            'Authorization': `Bearer ${token}`,
            "Content-Type": "multipart/form-data",
        }
    }
    return http.post('/api/uploadUser', data, params);
}



export const downloadTemp = () => {
    const token = getToken();
    const params = {
        headers: {
            'Authorization': `Bearer ${token}`,
        }
    }
    return http.get('/api/downloadTemp', params);
}


export const exportUserInfo = (data) => {
    const token = getToken();
    const params = {
        headers: {
            'Authorization': `Bearer ${token}`,
        },
    }
    return http.post('/api/exportUserInfo',data.user, params);
}

export const getRoleByPage = (data) => {
    const token = getToken();
    const params = {
        headers: {
            'Authorization': `Bearer ${token}`,
        },
    }
    return http.post(`/api/getRoleByPage?pageNum=${data.pageNum}&pageSize=${data.pageSize}`,data.role, params);
}

export const insertRole = (data) => {
    const token = getToken();
    const params = {
        headers: {
            'Authorization': `Bearer ${token}` // 使用模板字符串
        }
    }
    return http.post('/api/insertRole', data, params);
}


export const updateRole = (data) => {
    const token = getToken();
    const params = {
        headers: {
            'Authorization': `Bearer ${token}`, // 使用模板字符串
        }
    }
    return http.post('/api/updateRole', data, params);
}


export const deleteRoles = (roleIds) => {
    const token = getToken();
    const params = {
        headers: {
            'Authorization': `Bearer ${token}` // 使用模板字符串
        },
        params: {
            roleIds: roleIds
        }
    }
    return http.get('/api/deleteRoles',params);
}

export const getRoles = () => {
    const token = getToken();
    const params = {
        headers: {
            'Authorization': `Bearer ${token}` // 使用模板字符串
        },
    }
    return http.get('/api/getRoleIds',params);
}


export const getAllMenuIdByRoleId = (roleId) => {
    const token = getToken();
    const params = {
        headers: {
            'Authorization': `Bearer ${token}` // 使用模板字符串
        },
        params: {
            roleId: roleId
        }
    }
    return http.get('/api/menuIds',params);
}

export const assignPermission = (data) => {
    const token = getToken();
    const params = {
        headers: {
            'Authorization': `Bearer ${token}` // 使用模板字符串
        }
    }
    return http.post('/api/assignPermission',data,params);
}

